<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/**
<span class='line'>  2</span>  * @fileOverview Douglas Crockford’s JSON parser and serializer.
<span class='line'>  3</span>  */</span><span class="WHIT">
<span class='line'>  4</span> </span><span class="WHIT"> 
<span class='line'>  5</span> </span><span class="COMM">/**
<span class='line'>  6</span>  * @name JSON
<span class='line'>  7</span>  * @namespace
<span class='line'>  8</span>  */</span><span class="WHIT">
<span class='line'>  9</span> </span><span class="WHIT"> 
<span class='line'> 10</span> </span><span class="COMM">/**
<span class='line'> 11</span>  * This method produces a JSON text from a JavaScript value.
<span class='line'> 12</span>  * @name JSON.stringify
<span class='line'> 13</span>  * @function
<span class='line'> 14</span>  * @param {Object} value Any JavaScript value, usually an object or array.
<span class='line'> 15</span>  * @param {Function|String[]} [replacer] An optional parameter that determines how object
<span class='line'> 16</span>  *             values are stringified for objects. It can be a
<span class='line'> 17</span>  *             function or an array of strings.
<span class='line'> 18</span>  * @param {String|Number} [space] An optional parameter that specifies the indentation
<span class='line'> 19</span>  *           of nested structures. If it is omitted, the text will
<span class='line'> 20</span>  *           be packed without extra whitespace. If it is a number,
<span class='line'> 21</span>  *           it will specify the number of spaces to indent at each
<span class='line'> 22</span>  *           level. If it is a string (such as '\t' or '&nbsp;'),
<span class='line'> 23</span>  *           it contains the characters used to indent at each level.
<span class='line'> 24</span>  * @returns {String}
<span class='line'> 25</span>  */</span><span class="WHIT">
<span class='line'> 26</span> 
<span class='line'> 27</span> </span><span class="COMM">/**
<span class='line'> 28</span>  * This method parses a JSON text to produce an object or array.
<span class='line'> 29</span>  * @name JSON.parse
<span class='line'> 30</span>  * @function
<span class='line'> 31</span>  * @param {String} text The JSON text.
<span class='line'> 32</span>  * @param {Function} reviver A function that can filter and
<span class='line'> 33</span>  * transform the results. It receives each of the keys and values,
<span class='line'> 34</span>  * and its return value is used instead of the original value.
<span class='line'> 35</span>  * If it returns what it received, then the structure is not modified.
<span class='line'> 36</span>  * If it returns undefined then the member is deleted.
<span class='line'> 37</span>  * @returns {Object}
<span class='line'> 38</span>  */</span><span class="WHIT">
<span class='line'> 39</span> 
<span class='line'> 40</span> 
<span class='line'> 41</span> </span><span class="COMM">/*
<span class='line'> 42</span>     http://www.JSON.org/json2.js
<span class='line'> 43</span>     2011-02-23
<span class='line'> 44</span> 
<span class='line'> 45</span>     Public Domain.
<span class='line'> 46</span> 
<span class='line'> 47</span>     NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
<span class='line'> 48</span> 
<span class='line'> 49</span>     See http://www.JSON.org/js.html
<span class='line'> 50</span> 
<span class='line'> 51</span> 
<span class='line'> 52</span>     This code should be minified before deployment.
<span class='line'> 53</span>     See http://javascript.crockford.com/jsmin.html
<span class='line'> 54</span> 
<span class='line'> 55</span>     USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
<span class='line'> 56</span>     NOT CONTROL.
<span class='line'> 57</span> 
<span class='line'> 58</span> 
<span class='line'> 59</span>     This file creates a global JSON object containing two methods: stringify
<span class='line'> 60</span>     and parse.
<span class='line'> 61</span> 
<span class='line'> 62</span>         JSON.stringify(value, replacer, space)
<span class='line'> 63</span>             value       any JavaScript value, usually an object or array.
<span class='line'> 64</span> 
<span class='line'> 65</span>             replacer    an optional parameter that determines how object
<span class='line'> 66</span>                         values are stringified for objects. It can be a
<span class='line'> 67</span>                         function or an array of strings.
<span class='line'> 68</span> 
<span class='line'> 69</span>             space       an optional parameter that specifies the indentation
<span class='line'> 70</span>                         of nested structures. If it is omitted, the text will
<span class='line'> 71</span>                         be packed without extra whitespace. If it is a number,
<span class='line'> 72</span>                         it will specify the number of spaces to indent at each
<span class='line'> 73</span>                         level. If it is a string (such as '\t' or '&nbsp;'),
<span class='line'> 74</span>                         it contains the characters used to indent at each level.
<span class='line'> 75</span> 
<span class='line'> 76</span>             This method produces a JSON text from a JavaScript value.
<span class='line'> 77</span> 
<span class='line'> 78</span>             When an object value is found, if the object contains a toJSON
<span class='line'> 79</span>             method, its toJSON method will be called and the result will be
<span class='line'> 80</span>             stringified. A toJSON method does not serialize: it returns the
<span class='line'> 81</span>             value represented by the name/value pair that should be serialized,
<span class='line'> 82</span>             or undefined if nothing should be serialized. The toJSON method
<span class='line'> 83</span>             will be passed the key associated with the value, and this will be
<span class='line'> 84</span>             bound to the value
<span class='line'> 85</span> 
<span class='line'> 86</span>             For example, this would serialize Dates as ISO strings.
<span class='line'> 87</span> 
<span class='line'> 88</span>                 Date.prototype.toJSON = function (key) {
<span class='line'> 89</span>                     function f(n) {
<span class='line'> 90</span>                         // Format integers to have at least two digits.
<span class='line'> 91</span>                         return n &lt; 10 ? '0' + n : n;
<span class='line'> 92</span>                     }
<span class='line'> 93</span> 
<span class='line'> 94</span>                     return this.getUTCFullYear()   + '-' +
<span class='line'> 95</span>                          f(this.getUTCMonth() + 1) + '-' +
<span class='line'> 96</span>                          f(this.getUTCDate())      + 'T' +
<span class='line'> 97</span>                          f(this.getUTCHours())     + ':' +
<span class='line'> 98</span>                          f(this.getUTCMinutes())   + ':' +
<span class='line'> 99</span>                          f(this.getUTCSeconds())   + 'Z';
<span class='line'>100</span>                 };
<span class='line'>101</span> 
<span class='line'>102</span>             You can provide an optional replacer method. It will be passed the
<span class='line'>103</span>             key and value of each member, with this bound to the containing
<span class='line'>104</span>             object. The value that is returned from your method will be
<span class='line'>105</span>             serialized. If your method returns undefined, then the member will
<span class='line'>106</span>             be excluded from the serialization.
<span class='line'>107</span> 
<span class='line'>108</span>             If the replacer parameter is an array of strings, then it will be
<span class='line'>109</span>             used to select the members to be serialized. It filters the results
<span class='line'>110</span>             such that only members with keys listed in the replacer array are
<span class='line'>111</span>             stringified.
<span class='line'>112</span> 
<span class='line'>113</span>             Values that do not have JSON representations, such as undefined or
<span class='line'>114</span>             functions, will not be serialized. Such values in objects will be
<span class='line'>115</span>             dropped; in arrays they will be replaced with null. You can use
<span class='line'>116</span>             a replacer function to replace those with JSON values.
<span class='line'>117</span>             JSON.stringify(undefined) returns undefined.
<span class='line'>118</span> 
<span class='line'>119</span>             The optional space parameter produces a stringification of the
<span class='line'>120</span>             value that is filled with line breaks and indentation to make it
<span class='line'>121</span>             easier to read.
<span class='line'>122</span> 
<span class='line'>123</span>             If the space parameter is a non-empty string, then that string will
<span class='line'>124</span>             be used for indentation. If the space parameter is a number, then
<span class='line'>125</span>             the indentation will be that many spaces.
<span class='line'>126</span> 
<span class='line'>127</span>             Example:
<span class='line'>128</span> 
<span class='line'>129</span>             text = JSON.stringify(['e', {pluribus: 'unum'}]);
<span class='line'>130</span>             // text is '["e",{"pluribus":"unum"}]'
<span class='line'>131</span> 
<span class='line'>132</span> 
<span class='line'>133</span>             text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
<span class='line'>134</span>             // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
<span class='line'>135</span> 
<span class='line'>136</span>             text = JSON.stringify([new Date()], function (key, value) {
<span class='line'>137</span>                 return this[key] instanceof Date ?
<span class='line'>138</span>                     'Date(' + this[key] + ')' : value;
<span class='line'>139</span>             });
<span class='line'>140</span>             // text is '["Date(---current time---)"]'
<span class='line'>141</span> 
<span class='line'>142</span> 
<span class='line'>143</span>         JSON.parse(text, reviver)
<span class='line'>144</span>             This method parses a JSON text to produce an object or array.
<span class='line'>145</span>             It can throw a SyntaxError exception.
<span class='line'>146</span> 
<span class='line'>147</span>             The optional reviver parameter is a function that can filter and
<span class='line'>148</span>             transform the results. It receives each of the keys and values,
<span class='line'>149</span>             and its return value is used instead of the original value.
<span class='line'>150</span>             If it returns what it received, then the structure is not modified.
<span class='line'>151</span>             If it returns undefined then the member is deleted.
<span class='line'>152</span> 
<span class='line'>153</span>             Example:
<span class='line'>154</span> 
<span class='line'>155</span>             // Parse the text. Values that look like ISO date strings will
<span class='line'>156</span>             // be converted to Date objects.
<span class='line'>157</span> 
<span class='line'>158</span>             myData = JSON.parse(text, function (key, value) {
<span class='line'>159</span>                 var a;
<span class='line'>160</span>                 if (typeof value === 'string') {
<span class='line'>161</span>                     a =
<span class='line'>162</span> /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
<span class='line'>163</span>                     if (a) {
<span class='line'>164</span>                         return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
<span class='line'>165</span>                             +a[5], +a[6]));
<span class='line'>166</span>                     }
<span class='line'>167</span>                 }
<span class='line'>168</span>                 return value;
<span class='line'>169</span>             });
<span class='line'>170</span> 
<span class='line'>171</span>             myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
<span class='line'>172</span>                 var d;
<span class='line'>173</span>                 if (typeof value === 'string' &&
<span class='line'>174</span>                         value.slice(0, 5) === 'Date(' &&
<span class='line'>175</span>                         value.slice(-1) === ')') {
<span class='line'>176</span>                     d = new Date(value.slice(5, -1));
<span class='line'>177</span>                     if (d) {
<span class='line'>178</span>                         return d;
<span class='line'>179</span>                     }
<span class='line'>180</span>                 }
<span class='line'>181</span>                 return value;
<span class='line'>182</span>             });
<span class='line'>183</span> 
<span class='line'>184</span> 
<span class='line'>185</span>     This is a reference implementation. You are free to copy, modify, or
<span class='line'>186</span>     redistribute.
<span class='line'>187</span> */</span><span class="WHIT">
<span class='line'>188</span> 
<span class='line'>189</span> </span><span class="COMM">/*jslint evil: true, strict: false, regexp: false */</span><span class="WHIT">
<span class='line'>190</span> 
<span class='line'>191</span> </span><span class="COMM">/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
<span class='line'>192</span>     call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
<span class='line'>193</span>     getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
<span class='line'>194</span>     lastIndex, length, parse, prototype, push, replace, slice, stringify,
<span class='line'>195</span>     test, toJSON, toString, valueOf
<span class='line'>196</span> */</span><span class="WHIT">
<span class='line'>197</span> 
<span class='line'>198</span> 
<span class='line'>199</span> </span><span class="COMM">// Create a JSON object only if one does not already exist. We create the</span><span class="WHIT">
<span class='line'>200</span> </span><span class="COMM">// methods in a closure to avoid creating global variables.</span><span class="WHIT">
<span class='line'>201</span> 
<span class='line'>202</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">JSON</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>203</span> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">JSON</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>204</span> </span><span class="WHIT">    </span><span class="NAME">JSON</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>205</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>206</span> 
<span class='line'>207</span> </span><span class="PUNC">(</span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>208</span> </span><span class="WHIT">    </span><span class="STRN">"use strict"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>209</span> 
<span class='line'>210</span> </span><span class="WHIT">    </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">f</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>211</span> </span><span class="WHIT">        </span><span class="COMM">// Format integers to have at least two digits.</span><span class="WHIT">
<span class='line'>212</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">10</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">'0'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>213</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>214</span> 
<span class='line'>215</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">Date.prototype.toJSON</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>216</span> 
<span class='line'>217</span> </span><span class="WHIT">        </span><span class="NAME">Date.prototype.toJSON</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">key</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>218</span> 
<span class='line'>219</span> </span><span class="WHIT">            </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">isFinite</span><span class="PUNC">(</span><span class="NAME">this.valueOf</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT">
<span class='line'>220</span> </span><span class="WHIT">                </span><span class="NAME">this.getUTCFullYear</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">     </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">'-'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'>221</span> </span><span class="WHIT">                </span><span class="NAME">f</span><span class="PUNC">(</span><span class="NAME">this.getUTCMonth</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">'-'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'>222</span> </span><span class="WHIT">                </span><span class="NAME">f</span><span class="PUNC">(</span><span class="NAME">this.getUTCDate</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">      </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">'T'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'>223</span> </span><span class="WHIT">                </span><span class="NAME">f</span><span class="PUNC">(</span><span class="NAME">this.getUTCHours</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">     </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">':'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'>224</span> </span><span class="WHIT">                </span><span class="NAME">f</span><span class="PUNC">(</span><span class="NAME">this.getUTCMinutes</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">   </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">':'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'>225</span> </span><span class="WHIT">                </span><span class="NAME">f</span><span class="PUNC">(</span><span class="NAME">this.getUTCSeconds</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">   </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">'Z'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>226</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>227</span> 
<span class='line'>228</span> </span><span class="WHIT">        </span><span class="NAME">String.prototype.toJSON</span><span class="WHIT">      </span><span class="PUNC">=</span><span class="WHIT">
<span class='line'>229</span> </span><span class="WHIT">            </span><span class="NAME">Number.prototype.toJSON</span><span class="WHIT">  </span><span class="PUNC">=</span><span class="WHIT">
<span class='line'>230</span> </span><span class="WHIT">            </span><span class="NAME">Boolean.prototype.toJSON</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">key</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>231</span> </span><span class="WHIT">                </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.valueOf</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>232</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>233</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>234</span> 
<span class='line'>235</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">cx</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="REGX">/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>236</span> </span><span class="WHIT">        </span><span class="NAME">escapable</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="REGX">/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>237</span> </span><span class="WHIT">        </span><span class="NAME">gap</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>238</span> </span><span class="WHIT">        </span><span class="NAME">indent</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>239</span> </span><span class="WHIT">        </span><span class="NAME">meta</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">    </span><span class="COMM">// table of character substitutions</span><span class="WHIT">
<span class='line'>240</span> </span><span class="WHIT">            </span><span class="STRN">'\b'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'\\b'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>241</span> </span><span class="WHIT">            </span><span class="STRN">'\t'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'\\t'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>242</span> </span><span class="WHIT">            </span><span class="STRN">'\n'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'\\n'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>243</span> </span><span class="WHIT">            </span><span class="STRN">'\f'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'\\f'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>244</span> </span><span class="WHIT">            </span><span class="STRN">'\r'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'\\r'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>245</span> </span><span class="WHIT">            </span><span class="STRN">'"'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'\\"'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>246</span> </span><span class="WHIT">            </span><span class="STRN">'\\'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'\\\\'</span><span class="WHIT">
<span class='line'>247</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>248</span> </span><span class="WHIT">        </span><span class="NAME">rep</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>249</span> 
<span class='line'>250</span> 
<span class='line'>251</span> </span><span class="WHIT">    </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">quote</span><span class="PUNC">(</span><span class="NAME">string</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>252</span> 
<span class='line'>253</span> </span><span class="COMM">// If the string contains no control characters, no quote characters, and no</span><span class="WHIT">
<span class='line'>254</span> </span><span class="COMM">// backslash characters, then we can safely slap some quotes around it.</span><span class="WHIT">
<span class='line'>255</span> </span><span class="COMM">// Otherwise we must also replace the offending characters with safe escape</span><span class="WHIT">
<span class='line'>256</span> </span><span class="COMM">// sequences.</span><span class="WHIT">
<span class='line'>257</span> 
<span class='line'>258</span> </span><span class="WHIT">        </span><span class="NAME">escapable.lastIndex</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>259</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">escapable.test</span><span class="PUNC">(</span><span class="NAME">string</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">'"'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">string.replace</span><span class="PUNC">(</span><span class="NAME">escapable</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>260</span> </span><span class="WHIT">            </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">c</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">meta</span><span class="PUNC">[</span><span class="NAME">a</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>261</span> </span><span class="WHIT">            </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">c</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'string'</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">c</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>262</span> </span><span class="WHIT">                </span><span class="STRN">'\\u'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">'0000'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">a.charCodeAt</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toString</span><span class="PUNC">(</span><span class="NUMB">16</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>263</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">'"'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'"'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">string</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">'"'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>264</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>265</span> 
<span class='line'>266</span> 
<span class='line'>267</span> </span><span class="WHIT">    </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">str</span><span class="PUNC">(</span><span class="NAME">key</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">holder</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>268</span> 
<span class='line'>269</span> </span><span class="COMM">// Produce a string from holder[key].</span><span class="WHIT">
<span class='line'>270</span> 
<span class='line'>271</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">,</span><span class="WHIT">          </span><span class="COMM">// The loop counter.</span><span class="WHIT">
<span class='line'>272</span> </span><span class="WHIT">            </span><span class="NAME">k</span><span class="PUNC">,</span><span class="WHIT">          </span><span class="COMM">// The member key.</span><span class="WHIT">
<span class='line'>273</span> </span><span class="WHIT">            </span><span class="NAME">v</span><span class="PUNC">,</span><span class="WHIT">          </span><span class="COMM">// The member value.</span><span class="WHIT">
<span class='line'>274</span> </span><span class="WHIT">            </span><span class="NAME">length</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>275</span> </span><span class="WHIT">            </span><span class="NAME">mind</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">gap</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>276</span> </span><span class="WHIT">            </span><span class="NAME">partial</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>277</span> </span><span class="WHIT">            </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">holder</span><span class="PUNC">[</span><span class="NAME">key</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>278</span> 
<span class='line'>279</span> </span><span class="COMM">// If the value has a toJSON method, call it to obtain a replacement value.</span><span class="WHIT">
<span class='line'>280</span> 
<span class='line'>281</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'object'</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>282</span> </span><span class="WHIT">                </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">value.toJSON</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>283</span> </span><span class="WHIT">            </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">value.toJSON</span><span class="PUNC">(</span><span class="NAME">key</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>284</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>285</span> 
<span class='line'>286</span> </span><span class="COMM">// If we were called with a replacer function, then call the replacer to</span><span class="WHIT">
<span class='line'>287</span> </span><span class="COMM">// obtain a replacement value.</span><span class="WHIT">
<span class='line'>288</span> 
<span class='line'>289</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">rep</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>290</span> </span><span class="WHIT">            </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rep.call</span><span class="PUNC">(</span><span class="NAME">holder</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">key</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>291</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>292</span> 
<span class='line'>293</span> </span><span class="COMM">// What happens next depends on the value's type.</span><span class="WHIT">
<span class='line'>294</span> 
<span class='line'>295</span> </span><span class="WHIT">        </span><span class="KEYW">switch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>296</span> </span><span class="WHIT">        </span><span class="KEYW">case</span><span class="WHIT"> </span><span class="STRN">'string'</span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>297</span> </span><span class="WHIT">            </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">quote</span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>298</span> 
<span class='line'>299</span> </span><span class="WHIT">        </span><span class="KEYW">case</span><span class="WHIT"> </span><span class="STRN">'number'</span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>300</span> 
<span class='line'>301</span> </span><span class="COMM">// JSON numbers must be finite. Encode non-finite numbers as null.</span><span class="WHIT">
<span class='line'>302</span> 
<span class='line'>303</span> </span><span class="WHIT">            </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">isFinite</span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">String</span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'null'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>304</span> 
<span class='line'>305</span> </span><span class="WHIT">        </span><span class="KEYW">case</span><span class="WHIT"> </span><span class="STRN">'boolean'</span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>306</span> </span><span class="WHIT">        </span><span class="KEYW">case</span><span class="WHIT"> </span><span class="STRN">'null'</span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>307</span> 
<span class='line'>308</span> </span><span class="COMM">// If the value is a boolean or null, convert it to a string. Note:</span><span class="WHIT">
<span class='line'>309</span> </span><span class="COMM">// typeof null does not produce 'null'. The case is included here in</span><span class="WHIT">
<span class='line'>310</span> </span><span class="COMM">// the remote chance that this gets fixed someday.</span><span class="WHIT">
<span class='line'>311</span> 
<span class='line'>312</span> </span><span class="WHIT">            </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">String</span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>313</span> 
<span class='line'>314</span> </span><span class="COMM">// If the type is 'object', we might be dealing with an object or an array or</span><span class="WHIT">
<span class='line'>315</span> </span><span class="COMM">// null.</span><span class="WHIT">
<span class='line'>316</span> 
<span class='line'>317</span> </span><span class="WHIT">        </span><span class="KEYW">case</span><span class="WHIT"> </span><span class="STRN">'object'</span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>318</span> 
<span class='line'>319</span> </span><span class="COMM">// Due to a specification blunder in ECMAScript, typeof null is 'object',</span><span class="WHIT">
<span class='line'>320</span> </span><span class="COMM">// so watch out for that case.</span><span class="WHIT">
<span class='line'>321</span> 
<span class='line'>322</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>323</span> </span><span class="WHIT">                </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">'null'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>324</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>325</span> 
<span class='line'>326</span> </span><span class="COMM">// Make an array to hold the partial results of stringifying this object value.</span><span class="WHIT">
<span class='line'>327</span> 
<span class='line'>328</span> </span><span class="WHIT">            </span><span class="NAME">gap</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">indent</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>329</span> </span><span class="WHIT">            </span><span class="NAME">partial</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>330</span> 
<span class='line'>331</span> </span><span class="COMM">// Is the value an array?</span><span class="WHIT">
<span class='line'>332</span> 
<span class='line'>333</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Object.prototype.toString.apply</span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'[object Array]'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>334</span> 
<span class='line'>335</span> </span><span class="COMM">// The value is an array. Stringify every element. Use null as a placeholder</span><span class="WHIT">
<span class='line'>336</span> </span><span class="COMM">// for non-JSON values.</span><span class="WHIT">
<span class='line'>337</span> 
<span class='line'>338</span> </span><span class="WHIT">                </span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">value.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>339</span> </span><span class="WHIT">                </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>340</span> </span><span class="WHIT">                    </span><span class="NAME">partial</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">str</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="STRN">'null'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>341</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>342</span> 
<span class='line'>343</span> </span><span class="COMM">// Join all of the elements together, separated with commas, and wrap them in</span><span class="WHIT">
<span class='line'>344</span> </span><span class="COMM">// brackets.</span><span class="WHIT">
<span class='line'>345</span> 
<span class='line'>346</span> </span><span class="WHIT">                </span><span class="NAME">v</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">partial.length</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">'[]'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">gap</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT">
<span class='line'>347</span> </span><span class="WHIT">                    </span><span class="STRN">'[\n'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">gap</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">partial.join</span><span class="PUNC">(</span><span class="STRN">',\n'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">gap</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">'\n'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">mind</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">']'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>348</span> </span><span class="WHIT">                    </span><span class="STRN">'['</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">partial.join</span><span class="PUNC">(</span><span class="STRN">','</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">']'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>349</span> </span><span class="WHIT">                </span><span class="NAME">gap</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">mind</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>350</span> </span><span class="WHIT">                </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">v</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>351</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>352</span> 
<span class='line'>353</span> </span><span class="COMM">// If the replacer is an array, use it to select the members to be stringified.</span><span class="WHIT">
<span class='line'>354</span> 
<span class='line'>355</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">rep</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">rep</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'object'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>356</span> </span><span class="WHIT">                </span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rep.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>357</span> </span><span class="WHIT">                </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>358</span> </span><span class="WHIT">                    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">rep</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'string'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>359</span> </span><span class="WHIT">                        </span><span class="NAME">k</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rep</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>360</span> </span><span class="WHIT">                        </span><span class="NAME">v</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">str</span><span class="PUNC">(</span><span class="NAME">k</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>361</span> </span><span class="WHIT">                        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">v</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>362</span> </span><span class="WHIT">                            </span><span class="NAME">partial.push</span><span class="PUNC">(</span><span class="NAME">quote</span><span class="PUNC">(</span><span class="NAME">k</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">gap</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">': '</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">':'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">v</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>363</span> </span><span class="WHIT">                        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>364</span> </span><span class="WHIT">                    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>365</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>366</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>367</span> 
<span class='line'>368</span> </span><span class="COMM">// Otherwise, iterate through all of the keys in the object.</span><span class="WHIT">
<span class='line'>369</span> 
<span class='line'>370</span> </span><span class="WHIT">                </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">k</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>371</span> </span><span class="WHIT">                    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Object.prototype.hasOwnProperty.call</span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">k</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>372</span> </span><span class="WHIT">                        </span><span class="NAME">v</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">str</span><span class="PUNC">(</span><span class="NAME">k</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>373</span> </span><span class="WHIT">                        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">v</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>374</span> </span><span class="WHIT">                            </span><span class="NAME">partial.push</span><span class="PUNC">(</span><span class="NAME">quote</span><span class="PUNC">(</span><span class="NAME">k</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">gap</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">': '</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">':'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">v</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>375</span> </span><span class="WHIT">                        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>376</span> </span><span class="WHIT">                    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>377</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>378</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>379</span> 
<span class='line'>380</span> </span><span class="COMM">// Join all of the member texts together, separated with commas,</span><span class="WHIT">
<span class='line'>381</span> </span><span class="COMM">// and wrap them in braces.</span><span class="WHIT">
<span class='line'>382</span> 
<span class='line'>383</span> </span><span class="WHIT">            </span><span class="NAME">v</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">partial.length</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">'{}'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">gap</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT">
<span class='line'>384</span> </span><span class="WHIT">                </span><span class="STRN">'{\n'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">gap</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">partial.join</span><span class="PUNC">(</span><span class="STRN">',\n'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">gap</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">'\n'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">mind</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">'}'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>385</span> </span><span class="WHIT">                </span><span class="STRN">'{'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">partial.join</span><span class="PUNC">(</span><span class="STRN">','</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">'}'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>386</span> </span><span class="WHIT">            </span><span class="NAME">gap</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">mind</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>387</span> </span><span class="WHIT">            </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">v</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>388</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>389</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>390</span> 
<span class='line'>391</span> </span><span class="COMM">// If the JSON object does not yet have a stringify method, give it one.</span><span class="WHIT">
<span class='line'>392</span> 
<span class='line'>393</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">JSON.stringify</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>394</span> </span><span class="WHIT">        </span><span class="NAME">JSON.stringify</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">replacer</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">space</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>395</span> 
<span class='line'>396</span> </span><span class="COMM">// The stringify method takes a value and an optional replacer, and an optional</span><span class="WHIT">
<span class='line'>397</span> </span><span class="COMM">// space parameter, and returns a JSON text. The replacer can be a function</span><span class="WHIT">
<span class='line'>398</span> </span><span class="COMM">// that can replace values, or an array of strings that will select the keys.</span><span class="WHIT">
<span class='line'>399</span> </span><span class="COMM">// A default replacer method can be provided. Use of the space parameter can</span><span class="WHIT">
<span class='line'>400</span> </span><span class="COMM">// produce text that is more easily readable.</span><span class="WHIT">
<span class='line'>401</span> 
<span class='line'>402</span> </span><span class="WHIT">            </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>403</span> </span><span class="WHIT">            </span><span class="NAME">gap</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>404</span> </span><span class="WHIT">            </span><span class="NAME">indent</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>405</span> 
<span class='line'>406</span> </span><span class="COMM">// If the space parameter is a number, make an indent string containing that</span><span class="WHIT">
<span class='line'>407</span> </span><span class="COMM">// many spaces.</span><span class="WHIT">
<span class='line'>408</span> 
<span class='line'>409</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">space</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'number'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>410</span> </span><span class="WHIT">                </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">space</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>411</span> </span><span class="WHIT">                    </span><span class="NAME">indent</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">' '</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>412</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>413</span> 
<span class='line'>414</span> </span><span class="COMM">// If the space parameter is a string, it will be used as the indent string.</span><span class="WHIT">
<span class='line'>415</span> 
<span class='line'>416</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">space</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'string'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>417</span> </span><span class="WHIT">                </span><span class="NAME">indent</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">space</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>418</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>419</span> 
<span class='line'>420</span> </span><span class="COMM">// If there is a replacer, it must be a function or an array.</span><span class="WHIT">
<span class='line'>421</span> </span><span class="COMM">// Otherwise, throw an error.</span><span class="WHIT">
<span class='line'>422</span> 
<span class='line'>423</span> </span><span class="WHIT">            </span><span class="NAME">rep</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">replacer</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>424</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">replacer</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">replacer</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>425</span> </span><span class="WHIT">                    </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">replacer</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">'object'</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT">
<span class='line'>426</span> </span><span class="WHIT">                    </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">replacer.length</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">'number'</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>427</span> </span><span class="WHIT">                </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Error</span><span class="PUNC">(</span><span class="STRN">'JSON.stringify'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>428</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>429</span> 
<span class='line'>430</span> </span><span class="COMM">// Make a fake root object containing our value under the key of ''.</span><span class="WHIT">
<span class='line'>431</span> </span><span class="COMM">// Return the result of stringifying the value.</span><span class="WHIT">
<span class='line'>432</span> 
<span class='line'>433</span> </span><span class="WHIT">            </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">str</span><span class="PUNC">(</span><span class="STRN">''</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="STRN">''</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>434</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>435</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>436</span> 
<span class='line'>437</span> 
<span class='line'>438</span> </span><span class="COMM">// If the JSON object does not yet have a parse method, give it one.</span><span class="WHIT">
<span class='line'>439</span> 
<span class='line'>440</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">JSON.parse</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>441</span> </span><span class="WHIT">        </span><span class="NAME">JSON.parse</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">text</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">reviver</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>442</span> 
<span class='line'>443</span> </span><span class="COMM">// The parse method takes a text and an optional reviver function, and returns</span><span class="WHIT">
<span class='line'>444</span> </span><span class="COMM">// a JavaScript value if the text is a valid JSON text.</span><span class="WHIT">
<span class='line'>445</span> 
<span class='line'>446</span> </span><span class="WHIT">            </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">j</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>447</span> 
<span class='line'>448</span> </span><span class="WHIT">            </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">walk</span><span class="PUNC">(</span><span class="NAME">holder</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">key</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>449</span> 
<span class='line'>450</span> </span><span class="COMM">// The walk method is used to recursively walk the resulting structure so</span><span class="WHIT">
<span class='line'>451</span> </span><span class="COMM">// that modifications can be made.</span><span class="WHIT">
<span class='line'>452</span> 
<span class='line'>453</span> </span><span class="WHIT">                </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">k</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">v</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">holder</span><span class="PUNC">[</span><span class="NAME">key</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>454</span> </span><span class="WHIT">                </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'object'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>455</span> </span><span class="WHIT">                    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">k</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>456</span> </span><span class="WHIT">                        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Object.prototype.hasOwnProperty.call</span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">k</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>457</span> </span><span class="WHIT">                            </span><span class="NAME">v</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">walk</span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">k</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>458</span> </span><span class="WHIT">                            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">v</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>459</span> </span><span class="WHIT">                                </span><span class="NAME">value</span><span class="PUNC">[</span><span class="NAME">k</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">v</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>460</span> </span><span class="WHIT">                            </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>461</span> </span><span class="WHIT">                                </span><span class="KEYW">delete</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">[</span><span class="NAME">k</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>462</span> </span><span class="WHIT">                            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>463</span> </span><span class="WHIT">                        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>464</span> </span><span class="WHIT">                    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>465</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>466</span> </span><span class="WHIT">                </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">reviver.call</span><span class="PUNC">(</span><span class="NAME">holder</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">key</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>467</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>468</span> 
<span class='line'>469</span> 
<span class='line'>470</span> </span><span class="COMM">// Parsing happens in four stages. In the first stage, we replace certain</span><span class="WHIT">
<span class='line'>471</span> </span><span class="COMM">// Unicode characters with escape sequences. JavaScript handles many characters</span><span class="WHIT">
<span class='line'>472</span> </span><span class="COMM">// incorrectly, either silently deleting them, or treating them as line endings.</span><span class="WHIT">
<span class='line'>473</span> 
<span class='line'>474</span> </span><span class="WHIT">            </span><span class="NAME">text</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">String</span><span class="PUNC">(</span><span class="NAME">text</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>475</span> </span><span class="WHIT">            </span><span class="NAME">cx.lastIndex</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>476</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">cx.test</span><span class="PUNC">(</span><span class="NAME">text</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>477</span> </span><span class="WHIT">                </span><span class="NAME">text</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">text.replace</span><span class="PUNC">(</span><span class="NAME">cx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>478</span> </span><span class="WHIT">                    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">'\\u'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'>479</span> </span><span class="WHIT">                        </span><span class="PUNC">(</span><span class="STRN">'0000'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">a.charCodeAt</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toString</span><span class="PUNC">(</span><span class="NUMB">16</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>480</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>481</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>482</span> 
<span class='line'>483</span> </span><span class="COMM">// In the second stage, we run the text against regular expressions that look</span><span class="WHIT">
<span class='line'>484</span> </span><span class="COMM">// for non-JSON patterns. We are especially concerned with '()' and 'new'</span><span class="WHIT">
<span class='line'>485</span> </span><span class="COMM">// because they can cause invocation, and '=' because it can cause mutation.</span><span class="WHIT">
<span class='line'>486</span> </span><span class="COMM">// But just to be safe, we want to reject all unexpected forms.</span><span class="WHIT">
<span class='line'>487</span> 
<span class='line'>488</span> </span><span class="COMM">// We split the second stage into 4 regexp operations in order to work around</span><span class="WHIT">
<span class='line'>489</span> </span><span class="COMM">// crippling inefficiencies in IE's and Safari's regexp engines. First we</span><span class="WHIT">
<span class='line'>490</span> </span><span class="COMM">// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we</span><span class="WHIT">
<span class='line'>491</span> </span><span class="COMM">// replace all simple value tokens with ']' characters. Third, we delete all</span><span class="WHIT">
<span class='line'>492</span> </span><span class="COMM">// open brackets that follow a colon or comma or that begin the text. Finally,</span><span class="WHIT">
<span class='line'>493</span> </span><span class="COMM">// we look to see that the remaining characters are only whitespace or ']' or</span><span class="WHIT">
<span class='line'>494</span> </span><span class="COMM">// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.</span><span class="WHIT">
<span class='line'>495</span> 
<span class='line'>496</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="REGX">/^[\],:{}\s]*$/</span><span class="WHIT">
<span class='line'>497</span> </span><span class="WHIT">                    </span><span class="PUNC">.</span><span class="NAME">test</span><span class="PUNC">(</span><span class="NAME">text.replace</span><span class="PUNC">(</span><span class="REGX">/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'@'</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>498</span> </span><span class="WHIT">                        </span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="REGX">/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">']'</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>499</span> </span><span class="WHIT">                        </span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="REGX">/(?:^|:|,)(?:\s*\[)+/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>500</span> 
<span class='line'>501</span> </span><span class="COMM">// In the third stage we use the eval function to compile the text into a</span><span class="WHIT">
<span class='line'>502</span> </span><span class="COMM">// JavaScript structure. The '{' operator is subject to a syntactic ambiguity</span><span class="WHIT">
<span class='line'>503</span> </span><span class="COMM">// in JavaScript: it can begin a block or an object literal. We wrap the text</span><span class="WHIT">
<span class='line'>504</span> </span><span class="COMM">// in parens to eliminate the ambiguity.</span><span class="WHIT">
<span class='line'>505</span> 
<span class='line'>506</span> </span><span class="WHIT">                </span><span class="NAME">j</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">eval</span><span class="PUNC">(</span><span class="STRN">'('</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">text</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">')'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>507</span> 
<span class='line'>508</span> </span><span class="COMM">// In the optional fourth stage, we recursively walk the new structure, passing</span><span class="WHIT">
<span class='line'>509</span> </span><span class="COMM">// each name/value pair to a reviver function for possible transformation.</span><span class="WHIT">
<span class='line'>510</span> 
<span class='line'>511</span> </span><span class="WHIT">                </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">reviver</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT">
<span class='line'>512</span> </span><span class="WHIT">                    </span><span class="NAME">walk</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="STRN">''</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">j</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">j</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>513</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>514</span> 
<span class='line'>515</span> </span><span class="COMM">// If the text is not JSON parseable, then a SyntaxError is thrown.</span><span class="WHIT">
<span class='line'>516</span> 
<span class='line'>517</span> </span><span class="WHIT">            </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">SyntaxError</span><span class="PUNC">(</span><span class="STRN">'JSON.parse'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>518</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>519</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>520</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>521</span> 
<span class='line'>522</span> </span><span class="COMM">// Do not enumerate the new JSON methods.</span><span class="WHIT">
<span class='line'>523</span> </span><span class="COMM">// (These lines are not included in the original code by Crockford.)</span><span class="WHIT">
<span class='line'>524</span> </span><span class="NAME">Object.prototype.dontEnum</span><span class="PUNC">(</span><span class="STRN">"toJSONString"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>525</span> </span><span class="NAME">Object.prototype.dontEnum</span><span class="PUNC">(</span><span class="STRN">"parseJSON"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>526</span> 
<span class='line'>527</span> </span><span class="COMM">/**
<span class='line'>528</span>  * Create a JSONP-compatible response from the callback name and the desired data.
<span class='line'>529</span>  * @param {String} callback The name of the JSONP callback method
<span class='line'>530</span>  * @param {Object} data An arbitrary JavaScript object
<span class='line'>531</span>  */</span><span class="WHIT">
<span class='line'>532</span> </span><span class="NAME">JSON.pad</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>533</span> </span><span class="WHIT">   </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">callback</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>534</span> </span><span class="WHIT">      </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>535</span> </span><span class="WHIT">   </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>536</span> </span><span class="WHIT">   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"("</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">JSON.stringify</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">")"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>537</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>538</span> 
<span class='line'>539</span> </span><span class="COMM">/**
<span class='line'>540</span>  * Send a JSONP-compatible response if a the request contains callback data.
<span class='line'>541</span>  * This works out-of-the-box with jQuery but can be customized using the key argument.
<span class='line'>542</span>  * @param {Object} data An arbitrary JavaScript object
<span class='line'>543</span>  * @param {String} key The name of the property in req.data containing the JSONP callback method name
<span class='line'>544</span>  * @param {Boolean} resume Switch to define whether further processing should be continued or not
<span class='line'>545</span>  */</span><span class="WHIT">
<span class='line'>546</span> </span><span class="NAME">JSON.sendPaddedResponse</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">key</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">resume</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>547</span> </span><span class="WHIT">   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">req.data</span><span class="PUNC">[</span><span class="NAME">key</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="STRN">"callback"</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>548</span> </span><span class="WHIT">   </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">callback</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>549</span> </span><span class="WHIT">      </span><span class="NAME">res.contentType</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"text/javascript"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>550</span> </span><span class="WHIT">      </span><span class="NAME">res.write</span><span class="PUNC">(</span><span class="NAME">JSON.pad</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>551</span> </span><span class="WHIT">      </span><span class="NAME">resume</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">res.stop</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>552</span> </span><span class="WHIT">   </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>553</span> </span><span class="WHIT">   </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>554</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>555</span> </span></pre></body></html>